#SET(CMAKE_CROSS_COMPILER "/home/dzhang/anaconda3/envs/tf150-test/bin/")
#SET(CMAKE_C_COMPILER "${CMAKE_CROSS_COMPILER}gcc")
#SET(CMAKE_CXX_COMPILER "${CMAKE_CROSS_COMPILER}g++")

cmake_minimum_required (VERSION 3.0)
project (Monolith)
set(PROJECT_NAME Monolith)


option(MN_GFLAGS "Enable gflags" ON)
option(MN_GLOG "Enable glog" ON)
option(MN_FLATBUFFERS "Enable flatbuffers" ON)
option(MN_ABSEIL "Enable abseil" ON)
option(MN_OPENCV "Enable opencv" ON)
option(MN_SQLITE "Enable SQLiteCpp" ON)

if (MN_ABSEIL)
    add_subdirectory(third_party/abseil-cpp)
	include_directories(third_party/abseil-cpp)
	link_directories(${CMAKE_BINARY_DIR}/third_party/abseil-cpp/absl/strings)
	link_directories(${CMAKE_BINARY_DIR}/third_party/abseil-cpp/absl/numeric)
	link_directories(${CMAKE_BINARY_DIR}/third_party/abseil-cpp/absl/base)
endif ()

if (MN_GFLAGS)
    add_subdirectory(third_party/gflags)
    get_target_property(GFLAGS_INCLUDE_DIRS gflags INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(BEFORE "${GFLAGS_INCLUDE_DIRS}")
	link_directories(${CMAKE_BINARY_DIR}/third_party/gflags/)
endif ()

if (MN_GLOG)
    add_subdirectory(third_party/glog)
    get_target_property(GLOG_INCLUDE_DIRS glog INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(BEFORE "${GLOG_INCLUDE_DIRS}")
	link_directories(${CMAKE_BINARY_DIR}/third_party/glog)
endif ()

if (MN_FLATBUFFERS)
	add_subdirectory(third_party/flatbuffers)
	link_directories(${CMAKE_BINARY_DIR}/third_party/flatbuffers)
endif ()

if (MN_SQLITE)
	add_subdirectory(third_party/SQLiteCpp)
	get_target_property(SQLITE_INCLUDE_DIRS SQLiteCpp INTERFACE_INCLUDE_DIRECTORIES)
    include_directories(BEFORE "${SQLITE_INCLUDE_DIRS}")
	link_directories(${CMAKE_BINARY_DIR}/third_party/SQLiteCpp)
	link_directories(${CMAKE_BINARY_DIR}/third_party/SQLiteCpp/sqlite3)
endif ()

if (MN_OPENCV)
	find_package(OpenCV REQUIRED)
endif ()

add_subdirectory(third_party/MNN)
include_directories(third_party/MNN/include)
link_directories(${CMAKE_BINARY_DIR}/third_party/MNN)

# -latomic
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fPIC -O3 -std=c++14 -lpthread -lrt -ldl -pthread -fpermissive -lm")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fPIC -O3 -std=c99 -ldl -fpermissive")

link_directories(
	${CMAKE_BINARY_DIR}/lib
	# /home/dzhang/tools/MNN/lib
)

include_directories(
	${CMAKE_CURRENT_LIST_DIR}/
	${CMAKE_CURRENT_LIST_DIR}/third_party/eigen
	# ${CMAKE_CURRENT_LIST_DIR}/third_party/flatbuffers/include
	${CMAKE_CURRENT_LIST_DIR}/third_party/imageHelper
	# /home/dzhang/tools/MNN/include/
)

add_subdirectory(monolith/)

aux_source_directory(${PROJECT_SOURCE_DIR}/sample MAIN_SRC)
add_executable(${PROJECT_NAME} ${MAIN_SRC})
add_dependencies(${PROJECT_NAME} monolith_static MNN SQLiteCpp absl_strings)

set(LINK_LIB
    libmonolith.a
	libMNN.a
	libSQLiteCpp.a
	libsqlite3.a
	libabsl_strings.a
	libabsl_int128.a
	libabsl_throw_delegate.a
	libabsl_raw_logging_internal.a
	libabsl_base.a
	libgflags_nothreads.a
	libglog.a
	dl)

target_link_libraries(${PROJECT_NAME} ${LINK_LIB} ${OpenCV_LIBS})
